#ifndef _GOVT_ACCOUNT_HPP_
#define _GOVT_ACCOUNT_HPP_

/*******************************************************************************
 ** Government Sanctioned Espionage RPG Server                                **
 ** http://www.government-sanctioned.us/                                      **
 **===========================================================================**
 ** Name: account.hpp                                                            **
 ** Description:                         **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the LICENSE file within             **
 ** this distribution or at $WIKI/display/GOVT/License-software.              **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $GAME_DIR/LICENSE.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 ** Copyright (c) 2009-2012  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.                                                      **
 ******************************************************************************/
// $HeadURL$
// Modified $Date$ by $Author$
// $Id$

#include <odb/core.hxx>
#include "common.hpp"
#include "character.hpp"


enum class AccountState : uint8_t {
	Unknown,
	NewCharacter, AccountScreen, Tutorial,
	Playing, Idle
};

#define POWER_BUILDER	0x01
#define POWER_CONTROL 0x02
#define POWER_DIRECTOR 0x04
#define POWER_HANDLER 0x08

#define ACCT_COMPRESS 	0x01
#define ACCT_ANSI		0x02
#define ACCT_FXUNLOCK	0x04

//! @class Account
//! @brief Describes the game account a player has.
#pragma db object table("accounts")
class Account
{
public:
	Account();
	Account(const std::string & e, const std::string & p);

	typedef boost::shared_ptr<Account> pointer;

	static pointer Create() {
		return pointer(new Account());
	}
	static pointer Create(const std::string & e, const std::string & p) {
		return pointer(new Account(e,p));
	}

	// Getters
	const entity_t		ID() const { return _idaccount; }
	const std::string &	Email() const { return _email; }
	const std::string &	Password() const { return _passwd; }
	const boost::posix_time::ptime CreatedTS() const { return _created; }
	const boost::posix_time::ptime LastTS() const { return _last_login; }
	const boost::posix_time::ptime LogoutTS() const { return _logout; }
	const boost::posix_time::ptime IdleTS() const { return _idle; }
	const std::string &	LastIP() const { return _lastIP; }
	const uint8_t Power() const { return _power; }
	const uint16_t Flags() const { return _flags; }
// @Deprecated Account and character entities may exist at the same level as
// members of the same container class, like Client.
//	const entity_t		Char1() const { return _idchar1; }
//	const entity_t		Char2() const { return _idchar2; }
//	const entity_t		Char3() const { return _idchar3; }
	const entity_t		ColorScheme() const { return _color_scheme; }
	const int			Columns() const { return _terminal_cols; }
	const int			Rows() const { return _terminal_rows; }
	const AccountState	State() const { return _state; }
	const entity_t		FXUnlockProfession() const { return _fxUnlockProf; }

	// Setters
	void	Email(const std::string & e) { _email = e; }
	void	Password(const std::string & p) { _passwd = p; }
	void	CreatedTS(const boost::posix_time::ptime & p) { _created = p; }
	void	LastTS(const boost::posix_time::ptime & p) { _last_login = p; }
	void	IdleTS(const boost::posix_time::ptime & p) { _idle = p; }
	void	LogoutTS(const boost::posix_time::ptime & p) { _logout = p; }
	void	LastIP(const std::string & s) { _lastIP = s; }
	void	Power(const uint8_t p) { _power |= p; }
	void	Flags(const uint16_t f) { _flags |= f; }
	void	ZeroFlag(const uint16_t f) { _flags &= ~f; }
	void	ZeroFlags() { _flags = 0; }
//	void	Char1(const entity_t c) { _idchar1 = c; }
//	void	Char2(const entity_t c) { _idchar2 = c; }
//	void	Char3(const entity_t c) { _idchar3 = c; }
	void	ColorScheme(entity_t c) { _color_scheme = c; }
	void	Columns(const int c) { _terminal_cols = c; }
	void	Rows(const int r) { _terminal_rows = r; }
	void	State(const AccountState s) { _state = s; }
	void	FXUnlockProfession(const entity_t p) { _fxUnlockProf = p; }

private:
	friend class odb::access;

	#pragma db id auto
	entity_t		_idaccount;
	std::string		_email;
	std::string		_passwd;
	boost::posix_time::ptime _created;
	boost::posix_time::ptime _last_login;
	boost::posix_time::ptime _logout;
	boost::posix_time::ptime _idle;
	std::string		_lastIP;
	int				_acl;
	uint8_t			_power;
	uint16_t		_flags;
//	entity_t		_idchar1;
//	entity_t		_idchar2;
//	entity_t		_idchar3;
	entity_t		_color_scheme;
	int				_terminal_cols;
	int				_terminal_rows;
	AccountState	_state;
	entity_t		_fxUnlockProf;

	std::vector<Character::pointer>	_characters;

};


#endif /* _GOVT_ACCOUNT_HPP_ */
